#include<stdio.h>
int main()
{
    int time, command = 0;
    int lasttime = 0;
    int direction = 0;
    int distance = 0;
    int x = 0, y = 0;
    while(scanf("%d %d", &time, &command) != EOF)
    {
        if(time > 0)
            distance = (time - lasttime) * 10;
        switch(direction) //更新位置
        {
            case 0: y += distance; break;//北
            case 1: x += distance; break;//东
            case 2: y -= distance; break;//南
            case 3: x -= distance; break;//西
        }
        lasttime = time;
        if(command == 1)//向左转
            direction = (direction + 3) % 4;
        else if(command == 2)//向右转
            direction = (direction + 1) % 4;
        else if(command == 3)//结束
            break;
    }
    printf("%d %d", x, y);
    return 0;
}